 
import dayjs from 'dayjs'

 
 /**
  * 将时间转换为分:秒格式
  * @param time 时间数值
  * @param type 时间类型: ms:毫秒 s:秒 m:分钟 h:小时
  */
  const timeFilter = (time,type?) => {
    time = time | 0;
    
    let formatMillisecond:any ;

    switch (type) {
        case 'ms': formatMillisecond = dayjs(0).millisecond(Number.parseInt(time));
        case 's' : formatMillisecond = dayjs(0).second(Number.parseInt(time));
        case 'm' : formatMillisecond = dayjs(0).minute(Number.parseInt(time));
        case 'h' : formatMillisecond = dayjs(0).hour(Number.parseInt(time));
        default: formatMillisecond = dayjs(0).millisecond(Number.parseInt(time));
    }
    
  
    
    return `${formatZero(formatMillisecond.minute(),2)}:${formatZero(formatMillisecond.second(),2)}`;
  }

  const formatTime = (interval)=>{
    interval = interval | 0
    const m = (interval / 60) | 0
    const s = interval % 60
    return `${formatZero(m, 2)}:${formatZero(s, 2)}`
  }

  // 补0方法
  const formatZero = (num, len)=> {
    if (String(num).length > len) return num
    return (Array(len).join(0) + num).slice(-len)
  }

  export {timeFilter,formatTime,formatZero}